<template>
  <view class="floor-list">
    <view v-for="(floor, i ) in floorList" :key="i" class="floor-item">
      <image :src="floor.floor_title.image_src" class="floor-title"></image>
      <view class="floor-img-box">
        <navigator class="floor-img-left" :url="floor.product_list[0].url">
          <image :src="floor.product_list[0].image_src" :style="{width:
floor.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
        </navigator>
        <view class="floor-img-right">
          <navigator v-for="(rightFloor, j) in floor.product_list" :key="j" v-if="j !== 0" :url="rightFloor.url">
              <image :src="rightFloor.image_src" mode="widthFix" :style="{width:
              rightFloor.image_width + 'rpx'}"></image>
          </navigator>
        </view>

      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "home-floor",
    data() {
      return {
        floorList: []
      };
    },
    methods: {
      async initFloor() {
        await uni.$http.get('/api/public/v1/home/floordata').then(res => {
          if (res.data.meta.status !== 200) {
            return uni.$showMsg()
          }

          // 通过双层 forEach 循环，处理 URL 地址
          res.data.message.forEach(floor => {
            floor.product_list.forEach(prod => {
              prod.url = '/subpkg_goods/goods_list/goods_list?' +
                prod.navigator_url.split('?')[1]
            })
          })

          // 3.3 请求成功，为 data 中的数据赋值
          this.floorList = res.data.message
        })
      }
    },
    created() {
      // 初始化轮播图
      this.initFloor()
    }
  }
</script>

<style lang="scss">
  .floor-title {
    height: 60rpx;
    width: 100%;
  }

  .floor-img-box {

    display: flex;
    padding-left: 10rpx;

    .floor-img-left {}

    .floor-img-right {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
    }
  }
</style>
